﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Text;

namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class FirstBugTimeReport : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "FirstBugTimeReport";
            }
        }
        #region 属性 (查询条件)

        protected int showchart
        {
            get
            {
                return GetRequestValue<int>("showchart", 0);
            }
        }

        protected int Year
        {
            get
            {
                return GetRequestValue<int>("year", DateTime.Now.Year);
            }
        }     

      
        protected string stated
        {
            get
            {
                return Year.ToString() + "-01-01";
            }
        }

        protected string endd
        {
            get
            {
                return Year.ToString() + "-12-31 23:59:59";
            }
        }




        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
            if (GetRequestValue<string>("exportexecl", "0") == "1")
            {

            }
            AddLog(Permission.查看);
        }
        protected DataTable SUMDT = null;
        protected void DataBind()
        {
            DataTableCollection DTC = report2dts;
            this.rpMenu.DataSource = DTC[0];
            this.rpMenu.DataBind();
            SUMDT = DTC[1];
        }

        protected string GetYearList()
        {
            string liTemplete = "<option value='{0}' {1}>{0}年</option>";
            string rHtml = "";
            int nowYear = DateTime.Now.Year;
            for (int i = (nowYear - 3); i <= nowYear; i++)
            {
                rHtml = rHtml + string.Format(liTemplete, i, i == Year ? "selected" : "");
            }
            return rHtml;
        }


        private DataTableCollection _report2dts = null;
        private DataTableCollection report2dts
        {
            get
            {
                if (_report2dts == null)
                    _report2dts = UWarrantyCardController.GetFirstBugTimeReport(stated, endd);
                return _report2dts;
            }
        }
        /// <summary>
        /// 获取报表2 主表的X轴
        /// </summary>
        /// <returns></returns>
        protected string GetReport2JSCategories()
        {
            DataTable dtcl = report2dts[0];
            StringBuilder sb = new StringBuilder();
            //表头添加
            sb.Append("[");
            int rowindex = 1;
            foreach (DataRow dr in dtcl.Rows)
            {
                sb.AppendFormat("'{0}'", dr["月份"]);
                if (rowindex != dtcl.Rows.Count)
                {
                    sb.AppendFormat(",");
                }
                rowindex++;
            }
            sb.Append("]");
            string filedstr = sb.ToString();
            return filedstr;
        }

        protected string GetReport2JSSeries()
        {
            /*
             [{
                    name: 'John',
                    data: [5, 3, 4, 7, 2]
                }, {
                    name: 'Jane',
                    data: [2, 2, 3, 2, 1]
                }, {
                    name: 'Joe',
                    data: [3, 4, 4, 2, 5]
                }]
             */
            DataTable dtmain = report2dts[0];
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("[");
            int cNum = 1;
            foreach (DataColumn dc in dtmain.Columns)
            {
                if (dc.ColumnName == "月份")
                    continue;

                int rowNum = 1;
                string str直接 = "{name: '" + dc.ColumnName + "',data:[";
                foreach (DataRow dr in dtmain.Rows)
                {
                    str直接 += dr[dc.ColumnName];
                    if (rowNum != dtmain.Rows.Count)
                    {
                        str直接 += ",";
                    }
                    rowNum++;
                }
                str直接 += "]}";
                if (cNum != dtmain.Columns.Count - 1)
                {
                    str直接 += ",";
                }
                sb.AppendLine(str直接);
                cNum++;
            }

            sb.AppendLine("]");
            return sb.ToString();
        }

    }
}